package com.zline.foodraise.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.zline.foodraise.R;
import com.zline.foodraise.entity.CommentBean;
import com.zline.foodraise.entity.MomentBean;
import com.zline.foodraise.listener.DetailDynamicTopListener;
import com.zline.foodraise.util.ImageUtil;
import com.zline.foodraise.util.LUtil;
import com.zline.foodraise.view.DetailDynamicCommentItem;
import com.zline.foodraise.view.DetailDynamicCommentItem_;
import com.zline.foodraise.view.DetailDynamicHeader;
import com.zline.foodraise.view.DetailDynamicHeader_;
import com.zline.foodraise.view.RecyclerViewLoadMore_;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

/**
 * Created by heshantao on 15/10/16.
 */
@EBean
public class DetailDynamicAdapter extends HeaderBottomBaseRecyclerAdapter<CommentBean, DetailDynamicCommentItem> {
    private static final String LOG_TAG = DetailDynamicAdapter.class.getSimpleName();
    @RootContext
    Context cxt;
    MomentBean momentBean;
    DetailDynamicTopListener topListener;
    @Bean
    ImageUtil imageUtil;
    DisplayImageOptions options;

    public void setHeaderData(MomentBean momentBean) {
        this.momentBean = momentBean;
    }

    public void setDetailDynamicTopListener(DetailDynamicTopListener listener) {
        this.topListener = listener;
    }

    @Override
    protected HeaderWrapper onCreateHeaderView(ViewGroup parent, int viewType) {
        return new HeaderWrapper(DetailDynamicHeader_.build(cxt));
    }

    @Override
    protected DetailDynamicCommentItem onCreateItemView(ViewGroup parent, int viewType) {
        return DetailDynamicCommentItem_.build(cxt);
    }

    @Override
    protected BottomWrapper onCreateBottomView(ViewGroup parent, int viewType) {
        return new BottomWrapper(RecyclerViewLoadMore_.build(cxt));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ContentWrapper) {
            DetailDynamicCommentItem view = (DetailDynamicCommentItem) ((ContentWrapper) holder).getView();
            CommentBean commentBean = arrys.get(position - 1);
            view.setRecyclerItemClick(itemClicked);
            if (options == null) {
                options = imageUtil.
                        getDisplayImageOptions(R.mipmap.default_product_icon,
                                R.mipmap.default_product_icon, R.mipmap.default_product_icon);
            }
            view.bind(commentBean, position, options);
        } else if (holder instanceof HeaderWrapper) {
            DetailDynamicHeader header = (DetailDynamicHeader) ((HeaderWrapper) holder).getView();
            header.bindHeaderData(momentBean, itemClicked, topListener);
        }
    }
}
